

using System;
using System.Collections.Generic;
using System.Text;
using DataAccessLayer;
using EntityLayer;
using DataLayer;
using System.Data;
using InfraStructureLayer;

namespace BusinessLayer
{
	public class busArticleContents:BusinessBase
	{
		public busArticleContents() : base()
		{
		}

        public DataTable SelectArticleContentsByArticleId(entArticleContents parEntArticleContents)
        {
            try
            {
                datArticleContents insDatArticleContents = new datArticleContents();
                DbConnector insDbConnector = new DbConnector();
                DataTable dt = insDatArticleContents.SelectArticleContentsByArticleId(parEntArticleContents, insDbConnector);
                dt.Columns.Add("ArticleContentPublishLocations", typeof(string));

                datArticleContentPublishLocations insDatArticleContentPublishLocations = new datArticleContentPublishLocations();
                entArticleContentPublishLocations insEntArticleContentPublishLocations = new entArticleContentPublishLocations();
                foreach (DataRow dr in dt.Rows)
                {
                    string s = "";
                    if (dr["ArticleContentId"] != DBNull.Value)
                    {
                        insEntArticleContentPublishLocations.ArticleContentId = Convert.ToInt32(dr["ArticleContentId"]);
                        DataTable dtIn = insDatArticleContentPublishLocations.SelectArticleContentPublishLocationsByArticleContentId(insEntArticleContentPublishLocations, insDbConnector);
                        
                        foreach (DataRow drIn in dtIn.Rows)
                        {
                            s += drIn["ArticleContentPublishLocationName"].ToString() + "(" + drIn["ArticleContentPublishLocationLink"].ToString() + ")\r\n";
                        }
                        if (s.Length > 2)
                        {
                            s = s.Substring(0, s.Length - 2);
                        }
                    }
                    dr["ArticleContentPublishLocations"] = s;
                }
                return dt;
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
            return null;
        }
        public void SelectArticleContentsByArticleIdAndLanguageId(entArticleContents parEntArticleContents)
        {
            try
            {
                datArticleContents insDatArticleContents = new datArticleContents();
                DbConnector insDbConnector = new DbConnector();
                insDatArticleContents.SelectArticleContentsByArticleIdAndLanguageId(parEntArticleContents, insDbConnector);
                if (parEntArticleContents.ArticleContentId == 0)
                {
                    throw new SFBusinessException(GetErrorMessageMultilanguageString(43, new object[] { CurrentContext.Languages.Select("LanguageId=" + CurrentContext.LanguageId.ToString())[0]["LanguageName"].ToString() }));
                }
                parEntArticleContents.ArticleBody = GenerateHandlerLink(parEntArticleContents.ArticleBody);
                parEntArticleContents.ArticleSummary = GenerateHandlerLink(parEntArticleContents.ArticleSummary);
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }
        public void UpdateArticleContentRead(entArticleContents parEntArticleContents)
        {
            try
            {
                datArticleContents insDatArticleContents = new datArticleContents();
                DbConnector insDbConnector = new DbConnector();
                insDatArticleContents.UpdateArticleContentRead(parEntArticleContents, insDbConnector);
               
            }
            catch (SFException ex)
            {
                this.ErrorMessage = ex.Message;
            }
        }
	}
}